package com.tica.it.itmanage.controller;

import com.tica.catool.common.Result;
import com.tica.it.itmanage.config.jwt.JwtUtil;
import com.tica.it.itmanage.core.dto.RoleMenuDTO;
import com.tica.it.itmanage.core.dto.UserDetailDTO;
import com.tica.it.itmanage.server.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "角色管理")
@Slf4j
@RestController
@RequestMapping(value = "/role")
public class RoleController {


    @Autowired
    UserService userService;

    /**
     * 根据token获取用户信息
     *
     * @param req
     * @return
     */
    @ApiOperation(value = "根据ID查询用户")
    @GetMapping("/getRolePermission")
    //  @RequiresRoles()
    public Result<RoleMenuDTO> getRolePermission(HttpServletRequest req) {
        String token = req.getHeader(JwtUtil.HEADER);
        String username = JwtUtil.getUsername(token);
        RoleMenuDTO roleMenuDTO = userService.getPermissionByUsername(username);
        return Result.ok().data(roleMenuDTO);
    }

}
